const mongoose = require('mongoose');
const Challenge = require('../models/Challenge');
require('dotenv').config();

const challenges = [
  {
    title: "零塑料周",
    description: "一周内不使用任何一次性塑料制品",
    points: 100,
    duration: "7天",
    category: "lifestyle",
    difficulty: "中等",
    icon: "🌱",
    tasks: [
      { text: "自带购物袋", points: 20 },
      { text: "使用可重复使用的水杯", points: 20 },
      { text: "拒绝一次性餐具", points: 30 },
      { text: "选择无包装商品", points: 30 }
    ],
    tips: "准备一个环保购物套装，包含购物袋、水杯和餐具"
  },
  {
    title: "绿色出行",
    description: "连续5天使用公共交通或步行上下班",
    points: 80,
    duration: "5天",
    category: "transport",
    difficulty: "简单",
    icon: "🚲",
    tasks: [
      { text: "规划公交路线", points: 15 },
      { text: "准备自行车装备", points: 15 },
      { text: "记录每日出行方式", points: 25 },
      { text: "分享绿色出行体验", points: 25 }
    ],
    tips: "提前查看天气，合理安排出行时间"
  },
  {
    title: "节能达人",
    description: "将本月用电量较上月减少10%",
    points: 150,
    duration: "30天",
    category: "energy",
    difficulty: "困难",
    icon: "⚡",
    tasks: [
      { text: "记录用电数据", points: 30 },
      { text: "使用节能电器", points: 40 },
      { text: "养成随手关灯习惯", points: 40 },
      { text: "控制空调温度", points: 40 }
    ],
    tips: "使用智能插座监控用电量"
  },
  {
    title: "垃圾分类达人",
    description: "连续14天正确进行垃圾分类",
    points: 120,
    duration: "14天",
    category: "waste",
    difficulty: "中等",
    icon: "♻️",
    tasks: [
      { text: "学习垃圾分类知识", points: 20 },
      { text: "准备分类垃圾桶", points: 30 },
      { text: "正确进行日常分类", points: 40 },
      { text: "指导他人进行分类", points: 30 }
    ],
    tips: "下载垃圾分类指南APP，遇到不确定的物品可以查询"
  },
  {
    title: "食物零浪费",
    description: "一周内不浪费任何食物",
    points: 90,
    duration: "7天",
    category: "food",
    difficulty: "中等",
    icon: "🥗",
    tasks: [
      { text: "合理规划采购量", points: 20 },
      { text: "学习食材保存方法", points: 20 },
      { text: "制作剩余食材餐", points: 25 },
      { text: "记录每日食物消耗", points: 25 }
    ],
    tips: "建议制定每周菜单，根据菜单采购食材"
  },
  {
    title: "植物守护者",
    description: "种植和照顾一株植物30天",
    points: 100,
    duration: "30天",
    category: "garden",
    difficulty: "简单",
    icon: "🌿",
    tasks: [
      { text: "选择适合的植物", points: 20 },
      { text: "准备种植工具", points: 20 },
      { text: "日常浇水养护", points: 30 },
      { text: "记录生长过程", points: 30 }
    ],
    tips: "选择适合室内种植的植物，如绿萝、多肉等"
  },
  {
    title: "节能小卫士",
    description: "在日常生活中实践节能小妙招",
    points: 100,
    duration: "14天",
    category: "energy",
    difficulty: "简单",
    icon: "💡",
    tasks: [
      { text: "更换LED节能灯", points: 25 },
      { text: "使用自然光照明", points: 25 },
      { text: "合理设置空调温度", points: 25 },
      { text: "关闭待机设备", points: 25 }
    ],
    tips: "制作节能检查清单，养成良好习惯"
  },
  {
    title: "分类小能手",
    description: "学习并实践垃圾分类知识",
    points: 90,
    duration: "7天",
    category: "waste",
    difficulty: "简单",
    icon: "🗑️",
    tasks: [
      { text: "学习分类标准", points: 20 },
      { text: "准备分类容器", points: 20 },
      { text: "正确投放垃圾", points: 25 },
      { text: "教导家人分类", points: 25 }
    ],
    tips: "在家门口贴上分类指南，方便查看"
  },
  {
    title: "低碳饮食家",
    description: "选择低碳环保的饮食方式",
    points: 130,
    duration: "14天",
    category: "food",
    difficulty: "中等",
    icon: "🥬",
    tasks: [
      { text: "了解食物碳足迹", points: 30 },
      { text: "选购当季食材", points: 30 },
      { text: "减少肉类消费", points: 35 },
      { text: "记录饮食变化", points: 35 }
    ],
    tips: "可以使用碳足迹计算器评估饮食影响"
  },
  {
    title: "香草花园",
    description: "种植实用香草植物",
    points: 120,
    duration: "45天",
    category: "garden",
    difficulty: "中等",
    icon: "🌿",
    tasks: [
      { text: "选择香草品种", points: 30 },
      { text: "准备种植土壤", points: 30 },
      { text: "日常养护管理", points: 30 },
      { text: "运用香草烹饪", points: 30 }
    ],
    tips: "可以种植薄荷、罗勒等常用香草"
  },
  {
    title: "单车达人",
    description: "以自行车代替机动车出行",
    points: 120,
    duration: "14天",
    category: "transport",
    difficulty: "中等",
    icon: "🚴",
    tasks: [
      { text: "规划骑行路线", points: 30 },
      { text: "准备骑行装备", points: 30 },
      { text: "每日骑行记录", points: 30 },
      { text: "分享骑行体验", points: 30 }
    ],
    tips: "从短距离通勤开始尝试"
  },
  {
    title: "公交达人",
    description: "熟练使用公共交通系统",
    points: 90,
    duration: "7天",
    category: "transport",
    difficulty: "简单",
    icon: "🚌",
    tasks: [
      { text: "了解公交线路", points: 20 },
      { text: "办理公交卡", points: 20 },
      { text: "规划换乘方案", points: 25 },
      { text: "记录乘车体验", points: 25 }
    ],
    tips: "下载公交APP，实时查看车辆信息"
  },
  {
    title: "步行先锋",
    description: "培养步行出行习惯",
    points: 100,
    duration: "14天",
    category: "transport",
    difficulty: "简单",
    icon: "🚶",
    tasks: [
      { text: "规划步行路线", points: 25 },
      { text: "准备步行装备", points: 25 },
      { text: "坚持每日步行", points: 25 },
      { text: "记录步行数据", points: 25 }
    ],
    tips: "可以使用计步器记录每日步数"
  },
  {
    title: "共享出行",
    description: "使用共享交通工具",
    points: 110,
    duration: "14天",
    category: "transport",
    difficulty: "中等",
    icon: "🛵",
    tasks: [
      { text: "注册共享平台", points: 25 },
      { text: "了解使用规则", points: 25 },
      { text: "规范使用工具", points: 30 },
      { text: "评价使用体验", points: 30 }
    ],
    tips: "包括共享单车、电动车等多种方式"
  },
  {
    title: "低碳旅行家",
    description: "规划和实践低碳旅行",
    points: 150,
    duration: "7天",
    category: "transport",
    difficulty: "困难",
    icon: "🗺️",
    tasks: [
      { text: "选择绿色路线", points: 35 },
      { text: "使用公共交通", points: 35 },
      { text: "减少资源消耗", points: 40 },
      { text: "分享旅行经验", points: 40 }
    ],
    tips: "优先选择火车等低碳交通工具"
  },
  {
    title: "环保购物家",
    description: "践行环保购物理念",
    points: 100,
    duration: "14天",
    category: "lifestyle",
    difficulty: "简单",
    icon: "🛍️",
    tasks: [
      { text: "自带购物袋", points: 25 },
      { text: "选择简单包装", points: 25 },
      { text: "购买环保产品", points: 25 },
      { text: "拒绝过度包装", points: 25 }
    ],
    tips: "制作一个环保购物清单，随身携带"
  },
  {
    title: "极简生活",
    description: "开启极简主义生活方式",
    points: 120,
    duration: "30天",
    category: "lifestyle",
    difficulty: "中等",
    icon: "✨",
    tasks: [
      { text: "物品断舍离", points: 30 },
      { text: "整理收纳空间", points: 30 },
      { text: "建立物品清单", points: 30 },
      { text: "维持整洁习惯", points: 30 }
    ],
    tips: "每天处理一个区域，循序渐进"
  },
  {
    title: "环保清洁工",
    description: "使用环保清洁用品",
    points: 110,
    duration: "21天",
    category: "lifestyle",
    difficulty: "中等",
    icon: "🧹",
    tasks: [
      { text: "制作天然清洁剂", points: 25 },
      { text: "使用可降解用品", points: 25 },
      { text: "减少化学用品", points: 30 },
      { text: "分享清洁经验", points: 30 }
    ],
    tips: "可以用醋、小苏打等制作清洁剂"
  },
  {
    title: "阳台菜园",
    description: "在阳台种植蔬菜水果",
    points: 130,
    duration: "60天",
    category: "garden",
    difficulty: "中等",
    icon: "🌶️",
    tasks: [
      { text: "规划种植区域", points: 30 },
      { text: "选择适合植物", points: 30 },
      { text: "日常养护管理", points: 35 },
      { text: "收获和分享", points: 35 }
    ],
    tips: "可以从易种植的生菜、番茄开始"
  },
  {
    title: "废物利用达人",
    description: "创意改造废弃物品",
    points: 110,
    duration: "14天",
    category: "waste",
    difficulty: "中等",
    icon: "🎨",
    tasks: [
      { text: "收集可用废品", points: 25 },
      { text: "设计改造方案", points: 25 },
      { text: "制作创意作品", points: 30 },
      { text: "分享改造经验", points: 30 }
    ],
    tips: "可以参考网上的DIY教程获取灵感"
  },
  {
    title: "厨余管家",
    description: "合理利用厨余食材",
    points: 100,
    duration: "7天",
    category: "food",
    difficulty: "简单",
    icon: "🥘",
    tasks: [
      { text: "记录食材库存", points: 25 },
      { text: "规划食材利用", points: 25 },
      { text: "制作创意料理", points: 25 },
      { text: "分享节约心得", points: 25 }
    ],
    tips: "建立食材管理清单，定期检查使用"
  },
  {
    title: "绿色窗台",
    description: "打造室内绿色小天地",
    points: 90,
    duration: "30天",
    category: "garden",
    difficulty: "简单",
    icon: "🪴",
    tasks: [
      { text: "选择适合植物", points: 20 },
      { text: "布置种植空间", points: 20 },
      { text: "定期浇水施肥", points: 25 },
      { text: "观察记录生长", points: 25 }
    ],
    tips: "从耐养的多肉植物开始尝试"
  },
  {
    title: "能源监测员",
    description: "监测并优化家庭能源使用",
    points: 120,
    duration: "21天",
    category: "energy",
    difficulty: "中等",
    icon: "📊",
    tasks: [
      { text: "记录用电数据", points: 30 },
      { text: "分析用能模式", points: 30 },
      { text: "制定节能计划", points: 30 },
      { text: "执行优化方案", points: 30 }
    ],
    tips: "使用能源监测APP记录和分析数据"
  }
];

async function initChallenges() {
  try {
    await mongoose.connect(process.env.MONGODB_URI);
    console.log('连接到MongoDB成功');

    // 清除现有挑战
    await Challenge.deleteMany({});
    console.log('清除现有挑战数据');

    // 插入新挑战
    const result = await Challenge.insertMany(challenges);
    console.log(`成功创建 ${result.length} 个挑战`);

    console.log('挑战初始化完成');
  } catch (error) {
    console.error('初始化挑战失败:', error);
  } finally {
    await mongoose.connection.close();
  }
}

initChallenges(); 